'use strict';
const mongoose = require('mongoose');
const config = require('../config/config.unittest.js')({});
const fs = require('fs');
const readline = require('readline');
const moment = require('moment');
const _ = require('lodash');

let ParserBetter = require('../app/utils/rss/parser');
let parserBetter = new ParserBetter({timeout: 10000});

const UserModel = require('../app/model/User')({
  mongoose,
});
const TopicModel = require('../app/model/Topic')({
  mongoose,
});
const TopicCollectModel = require('../app/model/TopicCollect')({
  mongoose,
});

mongoose.connect(config.mongoose.url, config.mongoose.options, function (err) {
  if (err) {
    console.error('connect to %s error: ', config.mongoose, err.message);
    process.exit(1);
  }
});

main();

async function main() {
  await crud();
  process.exit(0);
}


async function crud() {
  const topics = await TopicModel.find({title: /最近这个《霍格沃兹/})
  console.log(topics.length);
  console.log(topics[0].title);
  console.log(topics[0].title.trim().replace(/[\u200B-\u200D\uFEFF]/g, ''));
  console.log(topics[0].title.trim().replace(/(^[\s\u200b]*|[\s\u200b]*$)/g, ''));
  console.log(topics[0].title.trim().replace(/\u8203/g, '').replace(/\uB200/g, ''));

  if(topics[0].title.charCodeAt(0) == 12644) {
    console.log(topics[0].title.substr(6, topics[0].title.length-1));
  }

  // for (let i = 0; i < topics.length; i++) {
  //   let topic = topics[i];
  //   if (!topic.pic) {
  //     continue;
  //   }
  //   topic.pic = topic.pic.replace('?x-oss-process=image/resize,w_332', '?x-oss-process=image/resize,w_500');
  //
  //   try {
  //     await topic.save();
  //     console.log(i, topics.length, topic.title);
  //   } catch (e) {
  //     console.error(i, topic.title);
  //     await TopicModel.remove({_id: topic._id});
  //   }
  // }


}
